<?php
require_once 'global.inc.php';

//check to see if they're logged in
if(!isset($_SESSION['admin_logged_in'])) {
	header("Location: index.php");
}

//get the user object from the session
$user = unserialize($_SESSION['admin_user']);


$productId = $_GET['product'];
$product = $GLOBALS['DB']->select("items", "item_id=".$productId);

?>
<!DOCTYPE html>
<html>
	<?php include 'header.php';?>
	<body>
		<!-- Navigation start -->
		<div class="navbar navbar-inverse navbar-fixed-top">
			<div class="navbar-inner">
				<div class="container">
					<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
					</button>
				</div>
			</div>
		</div>
		<!-- Navigation end -->

		<!-- Content start -->
		<div class="container">
			<div class="row">
				<div class="span12">
					<?php echo $user->username; ?>. You've been registered and logged in. Welcome! <a href="logout.php">Log Out</a> | <a href="index.php">Return to Homepage</a>
					<h1>Edit</h1>
					<a href="main.php">Product list</a>
				</div>
			</div>

			<div class="row">
				<div class="span12">
					<form action="update.php" method="post" enctype="multipart/form-data">
						<fieldset>
							<legend>Legend</legend>
								<label>Label name</label>
								<input name="name" type="input" value="<?php echo $product['item_name']?>">
								<label>Label price</label>
								<input name="price" type="input" value="<?php echo $product['price']?>">
								<label>Label picture</label>
								<img src="<?php echo BASE_URL.'upload/'.$product['picture']?>" alt="<?php echo $product['item_name'] ?>">
								<input type="file" name="picture">
								<label>Label description</label>
								<textarea name="description" rows="4" cols="100"><?php echo $product['description']?></textarea>
								<label>Label type</label>
								<input name="type" type="input" value="<?php echo $product['type']?>">
								<label>Label unit in stock</label>
								<input name="unitInStock" type="input" value="<?php echo $product['unit_instock']?>">
								<label>Label unit sold</label>
								<input name="unitSold" type="input" value="<?php echo $product['unit_sold']?>">

								<input name="product" type="hidden" value="<?php echo $product['item_id']?>">
								<button name="submit" type="submit" class="btn" value="1">Submit</button>
						</fieldset>
					</form>
				</div>
			</div>

		</div>


		<!-- Content end -->
		<?php include 'footer.php';?>
		<!-- Javascript -->
		<script src="js/jquery.js"></script>
		<script src="js/bootstrap.min.js"></script>
	</body>
</html>